<?php

  require_once ("../accesobd.php");
 

include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');


 
    $desven = "select  emp.idemp, 
                       emp.ciemp,
                       emp.nombreemp,
	               sum(fact.precioventa) as totalventa,
	               trunc((sum(fact.precioventa)* 100) / (select sum(precioventa) from factura)) as porcentaje
              from  empleado as emp, factura as fact
              where emp.idemp = fact.idemp
              group by emp.idemp
              order by 2 desc
              limit 5;
 ";
    
    $query = pg_query($conex,$desven) or die('Consulta fallida: ' . pg_last_error());
        // Redireccion
        pg_close($conex);
        //header("Location: ../../admin/gestionmesas.php")
        
        


 
     $cuerpo.= "<img src='../img/logo.png' /> <tr>
                        <td colspan='9' align='center'>5 Mejores vendedores</td></tr><table border=1 >
      
                        <thead>  
                        <tr>
                               



                                <th>Id</th>
                                <th>Cedula</th>
                                <th>Nombre</th>
                                <th>Total Venta</th>
                                <th>Porcentaje</th>
                                
                               
                        </tr>
                      </thead>"
            ?>
                 
             
               
<?php     
         while ($linea = pg_fetch_array($query, null, PGSQL_ASSOC)) {
                    //Guardando tuplas en el pdf
             

                    $cuerpo.= "
                        <tr>
                        <td>  ".$linea['idemp']."</td>
                        <td> ".$linea['ciemp']."</td>
                        <td> ".$linea['nombreemp']." </td>
                        <td> ".$linea['totalventa']." </td>
                        <td> ".$linea['porcentaje']."</td>                 
                        </tr>";
         }  
                 $cuerpo.= "</table>";
                
              crear_pdf($cuerpo,'5mejores');
    
?>